{% extends "base.html" %}
{% import "_my_wtf_macros.html" as my_wtf_macros %}

{% block title %}万屏时代OPC--浇水出价预览{% endblock %}

{% block panel_heading %}
  万屏时代OPC--浇水出价预览
{% endblock %}

{% block panel_body %}
    <form action="">
        <div class="well well-sm">基础参数</div>
        {{ my_wtf_macros.form_field(form.cate, div_col=4, label_col=4, field_col=6) }}
        {{ my_wtf_macros.form_field(form.size, div_col=4, label_col=4, field_col=6) }}
        {{ my_wtf_macros.form_field(form.color, div_col=4, label_col=4, field_col=6) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.span, div_col=4, label_col=4, field_col=6) }}
        {{ my_wtf_macros.form_field(form.type, div_col=4, label_col=4, field_col=6) }}
        {{ my_wtf_macros.form_field(form.city, div_col=4, label_col=4, field_col=6) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        <div class="well well-sm">浇水系数</div>
        <div class="form-group col-xs-6">
            <div class="row">
                <label class="control-label  col-xs-4" for="span">首次全局系数</label>
                <div class="col-xs-6">
                    <input class="form-control" id="global_factor" name="span" type="text" value="{{ watering_index }}">
                </div>
            </div>
        </div>
        <div class="form-group col-xs-6">
            <div class="row">
                <label class="control-label  col-xs-4" for="span">城市系数</label>
                <div class="col-xs-6">
                    <input class="form-control" id="city_factor" name="span" type="text" value="0">
                </div>
            </div>
        </div>
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        <div class="form-group col-xs-6">
            <div class="row">
                <label class="control-label  col-xs-4" for="span">二次全局系数</label>
                <div class="col-xs-6">
                    <input class="form-control" id="global_sec_factor" name="span" type="text" value="{{ sec_watering_index }}">
                </div>
            </div>
        </div>
        <div class="form-group col-xs-6">
            <div class="row">
                <label class="control-label  col-xs-4" for="span">多次全局系数</label>
                <div class="col-xs-6">
                    <input class="form-control" id="global_more_factor" name="span" type="text" value="{{ other_watering_index }}">
                </div>
            </div>
        </div>
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        <button class="btn btn-primary" id="preview" type="button">预览</button>
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        <br>
        <div class="well well-sm">结果</div>
        <div class="form-group col-xs-6">
            <div class="row">
                <label class="control-label  col-xs-4" for="span">首发原价</label>
                <div class="col-xs-6">
                    <input class="form-control" id="ori_bid_point" name="span" type="text" value="0">
                </div>
            </div>
        </div>
        <div class="form-group col-xs-6">
            <div class="row">
                <label class="control-label  col-xs-4" for="span">首次新价</label>
                <div class="col-xs-6">
                    <input class="form-control" id="new_bid_point" name="span" type="text" value="0">
                </div>
            </div>
        </div>
        <div class="form-group col-xs-6">
            <div class="row">
                <label class="control-label  col-xs-4" for="span">二发原价</label>
                <div class="col-xs-6">
                    <input class="form-control" id="sec_ori_bid_point" name="span" type="text" value="0">
                </div>
            </div>
        </div>
        <div class="form-group col-xs-6">
            <div class="row">
                <label class="control-label  col-xs-4" for="span">二发新价</label>
                <div class="col-xs-6">
                    <input class="form-control" id="sec_new_bid_point" name="span" type="text" value="0">
                </div>
            </div>
        </div>
        <div class="form-group col-xs-6">
            <div class="row">
                <label class="control-label  col-xs-4" for="span">多发原价</label>
                <div class="col-xs-6">
                    <input class="form-control" id="other_ori_bid_point" name="span" type="text" value="0">
                </div>
            </div>
        </div>
        <div class="form-group col-xs-6">
            <div class="row">
                <label class="control-label  col-xs-4" for="span">多发新价</label>
                <div class="col-xs-6">
                    <input class="form-control" id="other_new_bid_point" name="span" type="text" value="0">
                </div>
            </div>
        </div>
    </form>
{% endblock %}

{% block scripts %}
    {{ super() }}
    <script>
        $(document).ready(function () {
            $('#city').change(function() {
                var data = $(this).val();
                $.ajax({
                    url: "{{ url_for('water_bp.get_water_preview_factor') }}" + "?city=" + data,
                    cache: false
                }).done(function(data){
                    $('#city_factor').val(data['city_factor'])
                }).fail(function(data){
                    alert("查询失败,请联系管理员!")
                });
            });

            $('#preview').click(function() {
                var type = $('#type').val();
                var size = $('#size').val();
                var color = $('#color').val();
                var span = $('#span').val();
                var cate = $('#cate').val();
                var watering_index = $('#global_factor').val();
                var sec_watering_index = $('#global_sec_factor').val();
                var other_watering_index = $('#global_more_factor').val();
                var city_factor = $('#city_factor').val();
                var city = $('#city').val();

                if(span === ''){
                    alert('间距必填');
                    return false;
                }
                if(size === ''){
                    alert('面积必填');
                    return false;
                }

                if(city === '-1'){
                    alert('城市必选');
                    return false;
                }

                $.ajax({
                    type: "POST",
                    contentType: "application/json",
                    url: "{{ url_for('water_bp.water_preview') }}",
                    cache: false,
                    data: JSON.stringify({
                        'type': type,
                        'size': size,
                        'color': color,
                        'span': span,
                        'cate': cate,
                        'city_factor': city_factor,
                        'city': city,
                        'watering_index': watering_index,
                        'sec_watering_index': sec_watering_index,
                        'other_watering_index': other_watering_index
                    })
                }).done(function(data){
                    $('#ori_bid_point').val(data['first_old_value']);
                    $('#sec_ori_bid_point').val(data['second_old_value']);
                    $('#other_ori_bid_point').val(data['other_old_value']);
                    $('#new_bid_point').val(data['first_new_value']);
                    $('#sec_new_bid_point').val(data['second_new_value']);
                    $('#other_new_bid_point').val(data['other_new_value'])
                }).fail(function(data){
                    alert("查询失败,请联系管理员!")
                });
            });
        })
    </script>
{% endblock %}